import Vue from 'vue'
import Router from 'vue-router'
const originalPush = Router.prototype.push
Router.prototype.push = function push(location, onResolve, onReject) {
  if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)
  return originalPush.call(this, location).catch(err => err)
}
Vue.use(Router)
export default new Router({
  routes: [{
      path: '/index',
      component: () => import('../pages/index.vue'),
      children: [{
          path: '/home',
          component: () => import('../views/home.vue'),
          name: '小U商城'
        },
        {
          path: '/sort',
          component: () => import('../views/sort.vue'),
          name: '分类'
        },
        {
          path: '/cart',
          component: () => import('../views/cart.vue'),
          name: '购物车'
        },
        {
          path: '/mine',
          component: () => import('../views/mine.vue'),
          name: '我的',
        },
        {
          path: '',
          redirect: '/home'
        }
      ]
    },
    {
      path: '/goodslist',
      component: () => import('../pages/goodslist.vue'),
      name: '商品列表'
    },
    {
      path: '/goodsdeaitl',
      component: () => import('../pages/goodsdeaitl.vue'),
      name: '商品详情'
    },
    {
      path: '/register',
      component: () => import('../pages/register.vue'),
      name: '注册'
    },
    {
      path: '/login',
      component: () => import('../pages/login.vue'),
      name: '登录'
    },
    {
      path: '*',
      redirect: '/index'
    }
  ]
})
